package com.tiger.log.common.exception.handler;

import com.tiger.log.common.exception.member.ErrorException;
import com.tiger.log.common.response.Response;
import org.springframework.context.annotation.Description;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;

/**
 * @ClassName GlobalExceptionHandler
 * @Description 全局异常捕获器
 * @Author huxuehao
 **/
@ControllerAdvice
public class GlobalExceptionHandler {
    @ResponseBody
    @Description(value = "内部错误")
    @ExceptionHandler(value = Exception.class)
    public Response exceptionHandler(Exception e) {
        e.printStackTrace();
        return Response.error(500, "系统内部错误");
    }
    @ResponseBody
    @Description(value = "空指针异常")
    @ExceptionHandler(value = NullPointerException.class)
    public Response exceptionHandler(NullPointerException e) {
        e.printStackTrace();
        return Response.error(500, "空指针异常");
    }

    @ResponseBody
    @Description(value = "SQL异常处理")
    @ExceptionHandler(value = SQLException.class)
    public Response exceptionHandler(SQLException e) {
        e.printStackTrace();
        return Response.error(500, e.getMessage());
    }

    @ResponseBody
    @Description(value = "内部系统错误异常处理")
    @ExceptionHandler(value = ErrorException.class)
    public Response exceptionHandler(ErrorException e) {
        return Response.error(500, e.getMessage());
    }

}
